//
//  IsKindClassViewController.m
//  ReviewDemo
//
//  Created by 龙 on 2018/3/21.
//  Copyright © 2018年 long. All rights reserved.
//

#import "IsKindClassViewController.h"

#import "PeopleModel.h"
#import "Son.h"

@interface IsKindClassViewController ()

@end

@implementation IsKindClassViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self executeMethod];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)executeMethod
{
    PeopleModel *model = [[PeopleModel alloc] init];
    Son *sonModel = [[Son alloc] init];

    PeopleModel *peopleClass = [PeopleModel class];
    Son *sonClass = [Son class];
    NSObject *rootClass = [NSObject class];
    
    /*
         结论：isKindOfClass： 判断 一个对象的isa 或者 isa 的父类 是否属于 一个类
         isMemberOfClass 判断 一个对象的isa 是否属于一个类
     */
    
    NSLog(@"[model isKindOfClass:[PeopleModel class]] = %d",[model isKindOfClass:[PeopleModel class]]);//YES
    NSLog(@"[model isMemberOfClass:[PeopleModel class]] = %d",[model isMemberOfClass:[PeopleModel class]]);//YES
    NSLog(@"[peopleClass isKindOfClass:[PeopleModel class]] = %d",[peopleClass isKindOfClass:[PeopleModel class]]);//NO
    // 第一步 peopleClass 的 isa 指向它的 元类 显然不是 PeopleModel
    // 第二步 peopleClass 的 isa 的父类是 NSObject 的元类，显然不是 PeopleModel
    
    NSLog(@"[peopleClass isMemberOfClass:[PeopleModel class]] = %d",[peopleClass isMemberOfClass:[PeopleModel class]]);//NO
    // 第一步 peopleClass 的 isa 指向它的 元类 显然不是 PeopleModel

    NSLog(@"[rootClass isKindOfClass:[PeopleModel class]] = %d",[rootClass isKindOfClass:[NSObject class]]);//YES
    // 第一步 rootClass 的 isa 指向NSObject的 元类 显然不是 NSObject
    // 第二步 NSObject  的 isa 的父类是 NSObject

    NSLog(@"[rootClass isMemberOfClass:[PeopleModel class]] = %d",[rootClass isMemberOfClass:[NSObject class]]);//NO
    // 第一步 rootClass 的 isa 指向NSObject的 元类 显然不是 NSObject

    NSLog(@"[sonModel isKindOfClass:[PeopleModel class]] = %d",[sonModel isKindOfClass:[PeopleModel class]]);//YES
    NSLog(@"[sonModel isMemberOfClass:[PeopleModel class]] = %d",[sonModel isMemberOfClass:[PeopleModel class]]);//NO
    
    NSLog(@"[sonClass isKindOfClass:[PeopleModel class]] = %d",[sonClass isKindOfClass:[PeopleModel class]]);//NO
    NSLog(@"[sonClass isMemberOfClass:[PeopleModel class]] = %d",[sonClass isMemberOfClass:[PeopleModel class]]);//NO

    
    
}

@end
